<%@ page language="java" contentType="text/html;charset=utf-8" %>
<%@ include file="../../include/taglibs.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>商品添加</title>
    <script type="text/javascript" src="<c:url value='/scripts/boot.js'/>"></script>
    <script type="text/javascript" src="<c:url value='/scripts/Portal.js'/>"></script>
    <script type="text/javascript" src="<c:url value='/js/jquery.form.js'/>"></script>
    <link rel="stylesheet" href="<c:url value='/scripts/portal.css'/>"/>
	<script charset="utf-8" src="/kindeditor-4.1.1/kindeditor-min.js"></script>
	<script charset="utf-8" src="/kindeditor-4.1.1/lang/zh_CN.js"></script>

    <style type="text/css">
        body {
            margin: 0;
            padding: 0;
            border: 0;
            width: 100%;
            height: 100%;
            overflow: hidden;
        }
    </style>
</head>
<body>
<input type="hidden" name="action" id="action" class="mini-hidden">
<div id="tabs1" class="mini-tabs" activeIndex="0"
         style="width: 100%; height: 90%;" plain="false"
         onbeforeactivechanged="onBeforeActiveChanged">
         <div id="productBaseInfo" title="商品基本信息">
                <div style="padding: 5px;">
                <form id="form1" method="post" enctype="multipart/form-data">
				<input type="hidden" id="productId" name="id" class="mini-hidden">
				<input type="hidden" id="productDetailEn" name="productDetailEn" class="mini-hidden">
				<input type="hidden" id="productDetailZh" name="productDetailZh" class="mini-hidden">
                    <table style="table-layout: fixed;">
                       <tr>
                            <td style="width: 100px;">商品名称：</td>
                            <td style="width: 170px;"><input name="nameZh"
                                                             class="mini-textbox" required="true" style="width: 300px;"
                                                             emptyText="商品名称"/></td>
                            <td style="width: 170px;"><input name="nameEn"
                                                             class="mini-textbox" required="true" style="width: 300px;"
                                                             emptyText="英文名称"/></td>
                        </tr>
	                    <tr>
	                        <td>主图：</td>
	                        <td>
	                        <table>
	                        <tr>
	                        <td colspan="2"><input  id="mainFile" name="mainFile" type="file"/></td>
	                        <td><img id="imageview" style="width:130px;height:130px;"></td>
	                        </tr>
	                        </table>
	                        </td>
	                    </tr>
	                    <tr>
							<td style="width: 100px;">类别：</td>
							<td id="mianer" style="width: 500px;">
							<input id="categoryId" name="categoryId" allowInput="true"
							   class="mini-combobox" style="width: 200px;"
							   textField="nameEn" valueField="id" required="true"
							   emptyText="请选择..." url="/product/findAllCategory.action"
							   showNullItem="true" nullItemText="请选择..." />
							</td>
						</tr>
                       <tr>
                            <td style="width: 100px;">商品描述：</td>
                            <td style="width: 170px;"><input name="subtitleZh"
                                                             class="mini-textbox" required="true" style="width: 300px;"
                                                             emptyText="商品描述"/></td>
                            <td style="width: 170px;"><input name="subtitleEn"
                                                             class="mini-textbox" required="true" style="width: 300px;"
                                                             emptyText="英文描述"/></td>
                        </tr>
                        <tr>
                            <td style="width: 100px;">原价：</td>
                            <td colspan="2" style="width: 170px;">
                            <input required="true" name='originalPrice' format="$#,0.00" class='mini-spinner' minValue='1' maxValue='99999'/>
                            </td>
                        </tr>
                        <tr>
                            <td style="width: 100px;">售价：</td>
                            <td colspan="2" style="width: 170px;">
                            <input required="true"  name="sellingPrice" format="$#,0.00" changeOnMousewheel="false" class="mini-spinner"  minValue="1" maxValue="999999"/>
                            </td>
                        </tr>
                        <tr>
                            <td style="width: 100px;">阶梯次数：</td>
                            <td colspan="2" style="width: 170px;">
                            <input required="true"  name="stepCount" changeOnMousewheel="false" class="mini-spinner"  minValue="1" maxValue="999999"/>
                            </td>
                        </tr>
                        <tr>
                            <td style="width: 100px;">最小购买次数：</td>
                            <td colspan="2" style="width: 170px;">
                            <input required="true"  name="minCount" changeOnMousewheel="false" class="mini-spinner"  minValue="1" maxValue="999999"/>
                            </td>
                        </tr>
                        <tr>
                            <td style="width: 100px;">商品类型：</td>
                            <td colspan="2" style="width: 170px;"><input id="productType" name="productType"
                                                             class="mini-combobox" style="width: 300px;"
                                                             textField="text"
                                                             valueField="code" emptyText="请选择..."
                                                             url="/product/getProductType.action" required="true"
                                                             showNullItem="true" nullItemText="请选择..." required="true"/>
                            </td>
                        </tr>
                        <tr>
                            <td style="width: 100px;">寄送类型：</td>
                            <td colspan="2" style="width: 170px;"><input id="postType" name="postType"
                                                             class="mini-combobox" style="width: 300px;"
                                                             textField="text"
                                                             valueField="code" emptyText="请选择..."
                                                             url="/product/getProductPostType.action" required="true"
                                                             showNullItem="true" nullItemText="请选择..." required="true"/>
                            </td>
                        </tr>
                        <tr>
                            <td style="width: 100px;">商品状态：</td>
                            <td colspan="2" style="width: 170px;">
                            	<div id="status" name="status" class="mini-radiobuttonlist" repeatItems="2" repeatLayout="table" 
                            	repeatDirection="horizontal" textField="text" valueField="code"  url="/product/getProductStatus.action" value="0">
                            	</div>
                            </td>
                        </tr>
                        <tr>
                            <td style="width: 100px;">活动地区：</td>
                            <td colspan="2" style="width: 170px;">
                            	<div id="countryCode" name="countryCode" class="mini-radiobuttonlist" repeatItems="2" repeatLayout="table" 
                            	repeatDirection="horizontal" textField="text" valueField="code"  url="/product/getCountryCode.action" value="TT">
                            	</div>
                            </td>
                        </tr>
                    <tr>
                            <td colspan="3">
                            中文详情：<textarea name="contentEn" style="width:666px;height:400px;visibility:hidden;"></textarea>
                            </td>
                        </tr>
                    <tr>
                            <td colspan="3">
                            英文详情：<textarea name="contentZh" style="width:666px;height:400px;visibility:hidden;"></textarea>
                            </td>
                        </tr>
                    </table>
                    </form>
                </div>
        </div>
    </div>
    <div style="text-align: center; padding: 10px;">
        <a class="mini-button" onclick="SaveData"
           style="width: 60px; margin-right: 20px;">确定</a> <a
            class="mini-button" onclick="onCancel" style="width: 60px;">取消</a>
    </div>
<script type="text/javascript">
    mini.parse();
    var form = new mini.Form("form1");
    var editorEn;
    var editorZh;
	KindEditor.ready(function(K) {
		editorEn = K.create('textarea[name="contentEn"]', {
			allowFileManager : true,
			uploadJson:'/product/kindEditorUpload.action'
		});
	});
	KindEditor.ready(function(K) {
		editorZh = K.create('textarea[name="contentZh"]', {
			allowFileManager : true,
			uploadJson:'/product/kindEditorUpload.action'
		});
	});
    $(function() {  
        /*原理是把本地图片路径："D(盘符):/image/..."转为"http://..."格式路径来进行显示图片*/  
        $("#mainFile").change(function() {
        	var dataURL = getUrl(this);
            $("#imageview").attr("src",dataURL);  
        });  
    });
    function getUrl(e){
        var $file = $(e);  
        var objUrl = $file[0].files[0];  
        //获得一个http格式的url路径:mozilla(firefox)||webkit or chrome  
        var windowURL = window.URL || window.webkitURL;  
        //createObjectURL创建一个指向该参数对象(图片)的URL  
        return windowURL.createObjectURL(objUrl); 
    }
	//选中的skuId
    //标准方法接口定义
    function SetData(data) {
        mini.get("action").setValue(data.action);
        if (data.action == "edit") {
            mini.get("productId").setValue(data.menuId);
            data = mini.clone(data);
            $.ajax({
                url: "<c:url value='/product/editQueryProduct.action'/>",
                type: "post",
                data: {
                    id: data.id
                },
                cache: false,
                success: function (text) {
                    var o = mini.decode(text);
                    $("#imageview").attr("src",text.image);
                    if(null!=o.productDetailEn){
                    	editorEn.html(o.productDetailEn);
					}
                    if(null!=o.productDetailZh){
                    	editorZh.html(o.productDetailZh);
					}
                    form.setData(o);
                    form.setChanged(false);
                }
            });
        }
    }
    function SaveData() {
        form.validate();
        if (form.isValid() == false) return;
        var action = mini.get("action").getValue();
        var url;
        if ("edit" == action) {
            url = "<c:url value='/product/updateProductSubmit.action'/>";
        } else if ("new" == action) {
            url = "<c:url value='/product/addProductSubmit.action'/>";
        } else {
            return;
        }
        var contentEn=editorEn.html();
        var contentZh=editorZh.html();
        mini.get("productDetailEn").setValue(contentEn);
        mini.get("productDetailZh").setValue(contentZh);
        var msgid = mini.loading("数据处理中，请稍后......", "处理数据");
        $('#form1').ajaxSubmit({
            url: url,
            success: function () {
                mini.hideMessageBox(msgid);
                CloseWindow("save");
            },
            error: function (jqXHR, textStatus, errorThrown) {
                mini.hideMessageBox(msgid);
                mini.showMessageBox({
                    showModal: false,
                    width: 250,
                    title: "提示",
                    iconCls: "mini-messagebox-warning",
                    message: jqXHR.responseText,
                    timeout: 3000,
                    x: "right",
                    y: "bottom"
                });
            }
        });
    }

    function GetData() {
        var o = form.getData();
        return o;
    }
    function CloseWindow(action) {
        if (action == "close" && form.isChanged()) {
            if (confirm("数据被修改了，是否先保存？")) {
                return false;
            }
        }
        if (window.CloseOwnerWindow)
            return window.CloseOwnerWindow(action);
        else
            window.close();
    }
    function onOk(e) {
        SaveData();
    }
    function onCancel(e) {
        CloseWindow("close");
    }
</script>

</body>
</html>